package com.pda.xinmazhi.view.pagerview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;


import com.pda.xinmazhi.R;

import java.util.ArrayList;
import java.util.List;

public class MenuPagerView extends RelativeLayout {

    private Context context;

    private WrapContentHeightViewPager viewPager;

    private RecyclerView recyclerView;

    PointRvAdapter pointRvAdapter;

    public MenuPagerView(Context context) {
        this(context, null);
    }

    public MenuPagerView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MenuPagerView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
    }

  public   interface   onItemClickListener
    {
        void  onClick(String businessEntity);
    }

    private onItemClickListener itemClickListener;

    public  void  setOnItemListener(onItemClickListener itemClickListener)
    {
        this.itemClickListener=itemClickListener;
    }


    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        initView();
    }

    private void initView() {
        /*View view = LayoutInflater.from(context).inflate(R.layout.custom_menu_pager_view, null);
        viewPager = view.findViewById(R.id.viewPager);
        recyclerView = view.findViewById(R.id.recyclerView);
        addView(view);*/
    }

   /* public void initData(List<String> list, int num) {
        int addPager = list.size() % 12 == 0 ? 0 : 1;
        int pagerSize = list.size() / 12 + addPager;
        List<View> viewList = new ArrayList<>();
        for (int i = 0; i < pagerSize; i++) {
            View view = LayoutInflater.from(context).inflate(R.layout.custom_menu_recyclerview, null);
            RecyclerView rvMenu = view.findViewById(R.id.rvMenu);
            List<String> showMenuPagerList = new ArrayList<>();
            int max = Math.min(12 * (i + 1), list.size());
            for (int j = 12 * i; j < max; j++) {
                showMenuPagerList.add(list.get(j));
            }
            GridLayoutManager mGridLayoutManager = new GridLayoutManager(context, num);
            rvMenu.setLayoutManager(mGridLayoutManager);
            MenuRvAdapter menuRvAdapter = new MenuRvAdapter(showMenuPagerList,getContext());
            rvMenu.setAdapter(menuRvAdapter);
            menuRvAdapter.setOnItemListener(new MenuRvAdapter.onItemClickListener() {
                @Override
                public void onClick(String businessEntity) {
                    if(itemClickListener!=null)
                        itemClickListener.onClick(businessEntity);
                }
            });
            viewList.add(view);
        }
        ShowMenuAdapter adapter = new ShowMenuAdapter(viewList);
        viewPager.setAdapter(adapter);
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (pointRvAdapter != null) {
                    pointRvAdapter.setSelectedPoint(position);
                    pointRvAdapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        LinearLayoutManager pointManger = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
        recyclerView.setLayoutManager(pointManger);
        pointRvAdapter = new PointRvAdapter(pagerSize);
        recyclerView.setAdapter(pointRvAdapter);
    }*/


}
